<?php
/**
 * 易优CMS
 * ============================================================================
 * 版权所有 2016-2028 海南赞赞网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.eyoucms.com
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ============================================================================
 * Author: 小虎哥 <1105415366@qq.com>
 * Date: 2018-4-3
 */

namespace app\api\controller\v1;

use think\Db;
use think\Request;

class Dealer extends Base
{
    public $users;
    public $users_id;

    /**
     * 初始化操作
     */
    public function _initialize()
    {
        parent::_initialize();
        // 分销商模型
        $this->dealerModel = model('v1.Dealer');
        // 会员信息
        $this->users = $this->getUser();
        $this->users_id = !empty($this->users['users_id']) ? intval($this->users['users_id']) : 0;
    }

    public function dealer_action()
    {
        if (IS_AJAX) {
            $param = input('param.');
            if (empty($param['action'])) $param['action'] = '';

            // 判断执行操作
            if ('query' == $param['action']) {
                // 查询分销商申请数据
                $this->dealerModel->queryDealerApply();
            } else if ('getApply' == $param['action']) {
                // 获取分销商申请数据
                $this->dealerModel->getDealerApply($param, $this->users);
            } else if ('addApply' == $param['action']) {
                // 购物车数量操作
                $this->dealerModel->addDealerApply($param, $this->users);
            } else if ('selected' == $param['action']) {
                // 是否选中
                $this->dealerModel->updateCartSelected($param);
            } else if ('selectedAll' == $param['action']) {
                // 是否全部选中
                $this->dealerModel->updateCartAllSelected($param);
            } else if ('remove' == $param['action']) {
                // 移除购物车商品
                $this->dealerModel->removeCartGoods($param);
            } else if ('abnormal' == $param['action']) {
                // 删除购物车商品
                $this->dealerModel->abnormalCartGoods($param);
            } else {
                $this->error('请正确操作');
            }
        }
    }
}